package com.ZeroCarbon.domain.po;

import cn.hutool.core.bean.BeanUtil;
import com.ZeroCarbon.domain.dto.QuestionInfoDTO;
import com.ZeroCarbon.utils.JsonUtils;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.util.Map;

/**
 * 问题类
 *
 * @since 2024-10-14
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
@TableName("question")
public class QuestionInfo {
    /**
     * 账号
     */
    @TableId(type = IdType.INPUT)
    private String id;

    /**
     * 密保问题Json
     */
    private String questionJson;

    /**
     * PO转QuestionInfoDTO
     */
    public QuestionInfoDTO toQuestionInfoDTO() {
        //拷贝对象
        QuestionInfoDTO questionInfoDTO = BeanUtil.copyProperties(this, QuestionInfoDTO.class);
        //设置信息
        return questionInfoDTO.setQuestions(JsonUtils.JsonToObject(questionJson, Map.class));
    }
}
